`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    14:56:07 03/28/2014 
// Design Name: 
// Module Name:    vga_test_with_game_logic 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////

module vga_test_with_game_logic(
											clk,
										   kbd_clk,
											kbd_data,
											red,
											green,
											blue,
											HS,
											VS,
											audioOUT,
											gain,
											shutdown_bar
											);
			 								
input clk;
input kbd_clk;
input kbd_data;

output [2:0] red;
output [2:0] green; 
output [1:0] blue;
output HS;
output VS;
output audioOUT,gain,shutdown_bar;


wire reset;
wire start;
wire up,down,forward,back;
wire shoot,bomb;
wire enemy1_generation; //switch for enemy1 generation
wire enemy2_generation; //switch for enemy2 generation
wire enemy3_generation; 
wire enemy4_generation;
wire enemy5_generation; 
wire enemy6_generation;
wire bullet_enemy1;
wire collide_enemy1,collide_enemy2;
wire collide_enemy3,collide_enemy4;
wire collide_enemy5,collide_enemy6;
wire	bullet_generationleft , bullet_stationary,bullet_generationright, bullet_generation; //switch for bullet generation
wire[7:0] keyCode;				// key code extracted from kbdScan
wire keyRelease;					// key release signal from kdbScan
wire keyFlag;						// to indicate new keyCode data is ready
wire 	game_over;
wire		[3:0] lives;
wire		[15:0] scores;
wire level1,level2,level3,lvl1,lvl2;
wire collision;
wire [9:0] 	xpos_central, 
				ypos_central, 
				xpos_enemy1, 
				ypos_enemy1, 
				xpos_enemy2, 
				ypos_enemy2,
				xpos_enemy3, 
				ypos_enemy3,
				xpos_enemy4, 
				ypos_enemy4,
				xpos_enemy5, 
				ypos_enemy5,
				xpos_enemy6, 
				ypos_enemy6,
				xpos_bulletleft, 
				ypos_bulletleft,
				xpos_bulletright, 
				ypos_bulletright,	
				xpos_bullet,
				ypos_bullet,
				xpos_bullet_enemy1,
				ypos_bullet_enemy1,
				xpos_bullet_stationary,
				ypos_bullet_stationary,
				xpos_collide_enemy1,
				ypos_collide_enemy1,
				xpos_collide_enemy2,
				ypos_collide_enemy2,
				xpos_collide_enemy3,
				ypos_collide_enemy3,
				xpos_collide_enemy4,
				ypos_collide_enemy4,
				xpos_collide_enemy5,
				ypos_collide_enemy5,
				xpos_collide_enemy6,
				ypos_collide_enemy6,
				xpos_collision,
				ypos_collision;

	
vga_2 vga(	.collision(collision),
				.clk_old(clk), 
				.enable1(enemy1_generation),
				.enable2(enemy2_generation), 
				.enable4(enemy3_generation),
				.enable5(enemy4_generation),
				.enable6(enemy5_generation),
				.enable7(enemy6_generation),
				.enable8(bullet_on),
				.enable9(bullet_generation),
				.enable10(bullet_on1),
				.enable11(bullet_enemy1),
				.enable12(bullet_stationary),
				.enable13(collide_enemy1),
				.enable14(collide_enemy2),
				.enable15(collide_enemy3),
				.enable16(collide_enemy4),
				.enable17(collide_enemy5),
				.enable18(collide_enemy6),
				.red(red),
				.green(green),
				.blue(blue),
				.HS(HS),
				.VS(VS),
				.a(scores),
				.lives(lives),
				.level1(level1),
				.level2(level2),
				.level3(level3),
				.lvl1(lvl1),
				.lvl2(lvl2),
				.start(start),
				.X1(xpos_enemy1),
				.Y1(ypos_enemy1),
				.X2(xpos_enemy2),
				.Y2(ypos_enemy2),
				.X4(xpos_central),
				.Y4(ypos_central),
				.X5(xpos_collision),
				.Y5(ypos_collision),
				.X6(xpos_enemy3),
				.Y6(ypos_enemy3),
				.X7(xpos_enemy4),
				.Y7(ypos_enemy4),
				.X8(xpos_enemy5),
				.Y8(ypos_enemy5),
				.X9(xpos_enemy6),
				.Y9(ypos_enemy6),
				.X10(xpos_bulletleft),
				.Y10(ypos_bulletleft),
				.X11(xpos_bullet),
				.Y11(ypos_bullet),
				.X12(xpos_bulletright),
				.Y12(ypos_bulletright),
				.X13(xpos_bullet_enemy1),
				.Y13(ypos_bullet_enemy1),
				.X14(xpos_bullet_stationary),
				.Y14(ypos_bullet_stationary),
				.X15(xpos_collide_enemy1),
				.Y15(ypos_collide_enemy1),
				.X16(xpos_collide_enemy2),
				.Y16(ypos_collide_enemy2),
				.X17(xpos_collide_enemy3),
				.Y17(ypos_collide_enemy3),
				.X18(xpos_collide_enemy4),
				.Y18(ypos_collide_enemy4),
				.X19(xpos_collide_enemy5),
				.Y19(ypos_collide_enemy5),
				.X20(xpos_collide_enemy6),
				.Y20(ypos_collide_enemy6),
				.game_over(game_over)
				);

				
gamelogic4 game		( 	.clk(clk),
							.up(up),
							.down(down),
							.forward(forward),
							.back(back),
							.reset(reset),
							.enemy1_generation(enemy1_generation),
							.enemy2_generation(enemy2_generation),
							.enemy3_generation(enemy3_generation),
							.enemy4_generation(enemy4_generation),
							.enemy5_generation(enemy5_generation),
							.enemy6_generation(enemy6_generation),
							.bullet_enemy1(bullet_enemy1),
							.bullet_generation(bullet_generation),
							.bullet_stationary(bullet_stationary),
							.bullet_generationleft(bullet_generationleft),
							.bullet_generationright(bullet_generationright),
							.game_over(game_over),
							.lives(lives),
							.level1(level1),
							.level2(level2),
							.level3(level3),
							.lvl1(lvl1),
							.lvl2(lvl2),
							.scores(scores),
							.xpos_central(xpos_central), 
							.ypos_central(ypos_central), 
							.xpos_enemy1(xpos_enemy1), 
							.ypos_enemy1(ypos_enemy1), 
							.xpos_enemy2(xpos_enemy2),
							.ypos_enemy2(ypos_enemy2),
							.xpos_enemy3(xpos_enemy3),
							.ypos_enemy3(ypos_enemy3),
							.xpos_enemy4(xpos_enemy4),
							.ypos_enemy4(ypos_enemy4),
							.xpos_enemy5(xpos_enemy5),
							.ypos_enemy5(ypos_enemy5),
							.xpos_enemy6(xpos_enemy6),
							.ypos_enemy6(ypos_enemy6),
							.xpos_bullet(xpos_bullet), 
							.ypos_bullet(ypos_bullet),
							.xpos_bullet_enemy1(xpos_bullet_enemy1), 
							.ypos_bullet_enemy1(ypos_bullet_enemy1),
							.xpos_bullet_stationary(xpos_bullet_stationary), 
							.ypos_bullet_stationary(ypos_bullet_stationary),
							.xpos_bulletleft(xpos_bulletleft), 
							.ypos_bulletleft(ypos_bulletleft),
							.xpos_bulletright(xpos_bulletright), 
							.ypos_bulletright(ypos_bulletright),
							.xpos_collision(xpos_collision),
							.ypos_collision(ypos_collision),
							.xpos_collide_enemy1(xpos_collide_enemy1),
							.ypos_collide_enemy1(ypos_collide_enemy1),
							.xpos_collide_enemy2(xpos_collide_enemy2),
							.ypos_collide_enemy2(ypos_collide_enemy2),
							.xpos_collide_enemy3(xpos_collide_enemy3),
							.ypos_collide_enemy3(ypos_collide_enemy3),
							.xpos_collide_enemy4(xpos_collide_enemy4),
							.ypos_collide_enemy4(ypos_collide_enemy4),
							.xpos_collide_enemy5(xpos_collide_enemy5),
							.ypos_collide_enemy5(ypos_collide_enemy5),
							.xpos_collide_enemy6(xpos_collide_enemy6),
							.ypos_collide_enemy6(ypos_collide_enemy6),
							
							.collide_enemy1(collide_enemy1),
							.collide_enemy2(collide_enemy2),
							.collide_enemy3(collide_enemy3),
							.collide_enemy4(collide_enemy4),
							.collide_enemy5(collide_enemy5),
							.collide_enemy6(collide_enemy6),
							
						   .bullet_on(bullet_on),
							.bullet_on1(bullet_on1),
							.collision(collision)
							);
							
							
kbdScan kIN(.kbd_clk(kbd_clk), // clock pin from keyboard 
			.kbd_data(kbd_data), // data pin form keyboard 
			.keyCode(keyCode), 	// extracted key code from keyboard
			.keyFlag(keyFlag), 	// indicates when new key code is ready
			.keyRel(keyRelease)); // signal to release a pressed key


	//interpret key codes and update signals to game
keyDecoder KD(.keyRel(keyRelease), // signal to release a pressed key
			.keyCode(keyCode),   // extracted key code from keyboard
			.keyFlag(keyFlag),   // indicates when new key code is ready
			  // game control signal outputs: 
 		   .enter(start),   	 //  enter key
		   .up(up),		  // up arrow
		   .down(down),	  // down arrow
		   .left(back),		  // left arrow
		   .right(forward),    	// right arrow
		   .shoot(bullet_generationleft),  	  //  left ctrl key
	  	   .bomb(bullet_generationright),     	//  space bar
			.reset(reset));

AudioCore audio(
					.shoot(bullet_on || bullet_on1), 
					.enemyShoot(collide_enemy1 || collide_enemy2),
					.explode(collision), 
					.enemyExplode(collide_enemy1 || collide_enemy2 || collide_enemy3 || collide_enemy4 || collide_enemy5 || collide_enemy6),
					.music(), 
					.clk(clk),
					.audioOUT(audioOUT),
					.gain(gain), 
					.shutdown_bar(shutdown_bar));




							
endmodule
